<?php

include( "./admin/include/func.php");
include( "Pager/Pager.php");

$db = new db();
if ( ! $db->connect()) exit( mysql_error());

$db->sql = "SELECT COUNT(id)
            FROM hirdetes 
            WHERE regio=0 AND regio_nev!=''";		
$db->query();

$rpp = 500; //row per page
$tct = mysql_fetch_row($db->rs);
$tct = $tct[0];	//total count
$pager_options = array('mode' => 'Sliding', 'perPage' => $rpp, 'delta' => 2, 'totalItems' => $tct,);
$pager = @Pager::factory($pager_options);
list($from, $to) = $pager->getOffsetByPageId();

print "total count: $tct<br/>";
	
$db->sql = "SELECT azonosito,targy,regio_nev 
            FROM hirdetes
            WHERE regio=0 AND regio_nev!=''
            ORDER BY azonosito DESC 
            LIMIT " . ($from - 1) . ", $rpp";					
$db->query();

$hirds = array();
while ($h = mysql_fetch_assoc( $db->rs)) $hirds[] = $h; 

foreach ($hirds as $hird) {

	$db->sql = "SELECT id 
				FROM regio
				WHERE nev='".$hird['regio_nev']."'
				LIMIT 1";					
	$db->query();
	$rs = mysql_fetch_row( $db->rs);
	$regio_id = $rs[0]; 
	
	$hird['regio_id'] = $regio_id;
	
	//debug( $hird, 'hird');
	
	$db->sql = "UPDATE hirdetes SET regio='".$regio_id."' WHERE azonosito='".$hird['azonosito']."' LIMIT 1";
	$db->query();
}

?>

<br />

<div id="pager"><?php echo $pager->links; ?></div>
